package com.silence.gmall.config;

import com.silence.gmall.config.properties.MinioProperties;
import io.minio.MinioClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author silence
 * @Email 792245022@qq.com
 * @Date 2025-01-21 00:00
 * @Description MinIO 配置类
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
@ConditionalOnBean(MinioProperties.class)
@ConditionalOnProperty(prefix = "minio", name = "endpoint")
public class MinioConfig {

    /**
     * 配置
     */
    private final MinioProperties minioProperties;

    /**
     * 创建 MinioClient 客户端
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }
}